package cn.jdy.task.service.classify;


import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import cn.jdy.authority.entity.Organ;
import cn.jdy.authority.service.OrganService;
import cn.jdy.common.util.XMLUtil;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.plugins.entity.ApplyCash;
import cn.jdy.plugins.entity.CRateOrder;
import cn.jdy.plugins.entity.Member;
import cn.jdy.plugins.entity.Productx;
import cn.jdy.plugins.service.ApplyCashService;
import cn.jdy.plugins.service.CRateOrderService;
import cn.jdy.plugins.service.LiveService;
import cn.jdy.plugins.service.MemberService;
import cn.jdy.plugins.service.PointRecordService;
import cn.jdy.plugins.service.ProductxService;
import cn.jdy.plugins.service.WatchUserService;
import cn.jdy.plugins.service.WebsiteService;
import cn.jdy.plugins.wap.util.ChatUtil;
import cn.jdy.plugins.wap.util.HttpUtils;
import cn.jdy.plugins.wap.util.RedPacketUtil;
import cn.jdy.task.service.TaskGroup;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;




@TaskGroup("余额宝")
public class Websiteyeb implements Job {
	@Autowired
	private WebsiteService websiteService;
	@Autowired
	private CRateOrderService cRateOrderService;
	@Autowired
	private ProductxService productxService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private PointRecordService pointRecordService;
	@Autowired
	private ApplyCashService applyCashService;
	@Autowired
	private WatchUserService watchUserService;

	@Autowired
	private OrganService organService;
	@Autowired
	private LiveService liveService;

	//企业付款接口地址
	private static final String TRANSFERS_PAY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; 
	
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		try {
		
		List<Map<String,Object>> lsir  =	memberService.queryyueebao();
		for (Map<String, Object> member : lsir) {
			System.out.println(",,,执行");
		String id=	(String) member.get("id");
		Member member1=memberService.find(id);
			int de=(int) Math.floor(member1.getMoney()/100);
	  		CRateOrder redData =new CRateOrder();
	    	String orderNo = ChatUtil.generateString(18);
	    	redData.setOrderNo(orderNo);
	    	redData.setCreateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));
	  		Productx px=productxService.find(Long.valueOf(93));
	  		redData.setUsername(member1.getUserName());
	  		//istqsr
	  		redData.setTotal(de*100);
	  		redData.setIstqsr("0");
	  		redData.setProductxname(px.getTitle());
	  		redData.setImgUrl(px.getImgUrl());
	  		redData.setMemberid(member1.getId());
	  		redData.setMch_id("11");
	  		redData.setZfStatus("1");  //支付成功
	  		redData.setSendStatus("2");
	  		
	  		redData.setFs(de);
	  		redData.setUpdateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));
	  		cRateOrderService.save(redData);  //支付成功
	  //	int dwa=de*100;
//	double dea  =member.getMoney()-dwa;
	 	//member.setMoney(dea);
	//  	memberService.update(member);
		}

			//查询所有用户
			
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "invoke", e);
		}
	}
	
	
	public static void main(String[] args) {
		System.out.println((int)Math.floor(101/100));
	}

}
